home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl\vcl.h>
- #pragma hdrstop
-
- #include "SMTPTstU.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TMainForm *MainForm;
- //---------------------------------------------------------------------------
- __fastcall TMainForm::TMainForm(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- //
- // NOTE: You mail have to specifically set the name of your
- // mail server for the Host property. In some cases just
- // "mail" works. In other cases you have to specify the
- // exact mail server name. If your SMTP server is a secure
- // server then you may have to set the UserID property to
- // your user name as well.
- //
- void __fastcall TMainForm::ConnectBtnClick(TObject *Sender)
- {
- SMTP->Host = "mail";
- SMTP->Connect();
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TMainForm::SMTPSuccess(TObject *Sender)
- {
- StatusBar->SimpleText = "Mail Sent!";
- SMTP->Disconnect();
- DisconnectBtn->Enabled = false;
- SendBtn->Enabled = false;
- ConnectBtn->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::SMTPFailure(TObject *Sender)
- {
- StatusBar->SimpleText = "Mail Failure";
- SMTP->Disconnect();
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TMainForm::SendBtnClick(TObject *Sender)
- {
- SMTP->PostMessage->FromAddress = FromEdit->Text;
- SMTP->PostMessage->ToAddress->Add(ToEdit->Text);
- SMTP->PostMessage->Subject = SubjectEdit->Text;
- SMTP->PostMessage->Body->Assign(Message->Lines);
- SMTP->SendMail();
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::DisconnectBtnClick(TObject *Sender)
- {
- StatusBar->SimpleText = "Not Connected";
- SMTP->Disconnect();
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::SMTPConnect(TObject *Sender)
- {
- StatusBar->SimpleText = "Connected";
- DisconnectBtn->Enabled = true;
- SendBtn->Enabled = true;
- ConnectBtn->Enabled = false;
- // It would make sense to send the mail when connected to the SMTP
- // server. Unfortunately that wasn't working at the time this program
- // was written. As a workaround you could post a user-defined message
- // to yourself from here and send the e-mail messsage in the handler
- // for the user-defined message.
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TMainForm::SMTPDisconnect(TObject *Sender)
- {
- // As of this writing this event is fired even after the object has
- // been destroyed. The following line prevents an Access Violation
- // if that happens.
- if (!SendBtn) return;
-
- DisconnectBtn->Enabled = false;
- SendBtn->Enabled = false;
- ConnectBtn->Enabled = true;
- }
- //---------------------------------------------------------------------------
-
-